package com.nanyang.tms.controller.company;

import com.nanyang.common.core.annotation.BindParam;
import com.nanyang.common.core.dict.CommonEnum;
import com.nanyang.common.core.domain.ApiResult;
import com.nanyang.common.core.exception.ServiceException;
import com.nanyang.common.core.page.PageBean;
import com.nanyang.tms.api.dto.request.companytransaction.CompanyTransactionQueryRequest;
import com.nanyang.tms.api.dto.request.companytransaction.FrontTransactionQueryRequest;
import com.nanyang.tms.api.dto.response.companytransaction.CompanyTransactionResponse;
import com.nanyang.tms.api.dto.response.companytransaction.FrontTransactionResponse;
import com.nanyang.tms.api.service.companytransaction.CompanyTransactionRpcService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/companytransaction")
public class CompanyTransactionController {
    @Reference(version = "1.0.0", timeout = 10000, check = false)
    private CompanyTransactionRpcService companyTransactionRpcService;
    /**
     * <p>listCompanyStored</p>
     * <p>Description:客户交易明细列表</p>
     *
     * @param param
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public ApiResult<PageBean<CompanyTransactionResponse>> listTransaction(@RequestBody CompanyTransactionQueryRequest param) {
        ApiResult<PageBean<CompanyTransactionResponse>> apiResult = companyTransactionRpcService.listTransaction(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }

    /**
     * <p>listCompanyStored</p>
     * <p>Description:前台-客户交易明细列表</p>
     *
     * @param param
     * @return
     */
    @BindParam
    @RequestMapping(value = "/listFront", method = RequestMethod.POST)
    public ApiResult<PageBean<FrontTransactionResponse>> listFrontTransaction(@BindParam @RequestBody FrontTransactionQueryRequest param) {
        ApiResult<PageBean<FrontTransactionResponse>> apiResult = companyTransactionRpcService.listFrontTransaction(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }
}
